# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  def generate_menu( *items )
    result = ''
    items.each{ |i| result << generate_menu_pair( i[0], i[1]) }
    result
  end
  
  def generate_menu_pair( name, model )
    
    edit_link = link_to 'Criar', :controller => name, :action => :new
    list_link = link_to 'Listar', :controller => name, :action => :list
    
    %Q{<p>#{model}</p>
        <ul>
          <li>#{edit_link}</li>
          <li>#{list_link}</li>
       </ul>}
  end
  
  def buscar_tipos
    Tipo.find( :all, :order => :nome).map { |i| [i.nome, i.id] } 
  end

  def buscar_marcas
    Marca.find( :all, :order => :nome).map { |i| [i.nome, i.id] } 
  end
  
end
